import React from 'react';
import ReactDOM from 'react-dom';
import Button from "../../../node_modules/react-bootstrap/lib/Button";
import Modal from "../../../node_modules/react-bootstrap/lib/Modal";


let Confirm = React.createClass({
    getInitialState: function () {
        return {
            open: false,
            msg:"",
            callback:null
        }
    },
    componentDidMount:function(){
        var obThis = this;
        window.confirm = function(msg,cb){
            obThis.setState({
                open: true,
                msg:msg,
                callback:(typeof(cb) == 'function')?cb:null
            });
        }
    },
    handleOpen: function () {
        this.setState({open: true});
    },

    handleClose: function () {
        this.setState({open: false});
    },
    handleConfirm:function(){
        this.state.callback();
        this.handleClose();
    },
    render() {
        return (
        <Modal
            show={this.state.open}
            style={{borderRadius:"0",height:"300px",width:"500px"}}
        >
            <Modal.Header style={{background:"#383F45"}}>
                <Modal.Title style={{color:"white"}}>
                    <img src="/res/image/prompt.png" style={{float:"left"}}/>
                    <span style={{marginLeft: "10px",letterSpacing:"2px"}}>提示</span>
                    <img src="/res/image/close.png" style={{float:"right",cursor:"pointer",marginTop:" 5.5px"}}
                         onClick={this.handleClose}/>
                </Modal.Title>
            </Modal.Header>
            <Modal.Body style={{textAlign: "center",paddingTop: "50px"}}>
                {this.state.msg}
            </Modal.Body>
            <Modal.Footer style = {{textAlign: "center",border: "none",fontFamily:'Microsoft YaHei'}}>
                <Button onClick={this.handleConfirm}
                        style={{backgroundColor: "#555", borderColor: "#555",width:"70px",margin:'12'}}
                        bsStyle="primary">确定</Button>
                <Button onClick={this.handleClose}
                        style={{backgroundColor:"#fff",color: "#555", borderColor: "#555",width:"70px",margin:'12'}}
                        bsStyle="primary">取消</Button>
            </Modal.Footer>
        </Modal>
        );
    }
});
module.exports = Confirm;
